﻿using DotNetCore.CAP;
using DotNetCore.CAP.Internal;
using DotNetCore.CAP.Transport;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace CapHttp.Core;

internal class HttpOptionsExtension : ICapOptionsExtension
{
    public void AddServices(IServiceCollection services)
    {
        services.AddSingleton(new CapMessageQueueMakerService());
        
        services.Replace(ServiceDescriptor.Singleton(typeof(IConsumerServiceSelector),
            x => new CapConsumerServiceSelector(x)));

        services.AddSingleton<IDistributedEventPublisher, CapEventPublisher>();

        services.AddHttpClient();

        services.AddSingleton<HttpConsumerMiddleware>();
        services.AddSingleton<IConsumerClientFactory, HttpConsumerClientFactory>();
        services.AddSingleton<ITransport, HttpTransport>();
    }
}